package controlLayer;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The test class PersonControllerTest.
 *
 * @author  Gruppe E
 * @version 1.0
 */
public class PersonControllerTest
{
    /**
     * Default constructor for test class PersonControllerTest
     */
    public PersonControllerTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }

    /**
     * Method testDeletePerson
     * 
     * Tests DeletePerson
     *
     */
    @Test
    public void testDeletePerson()
    {
        controlLayer.PersonController personCo1 = new controlLayer.PersonController();
        assertEquals(true, personCo1.createPerson("test", "test", "test", "test", "123"));
        assertEquals(false, personCo1.deletePerson("234")); //slet person med forkert nummer
        assertEquals(true, personCo1.deletePerson("123")); //slet person med rigtigt nummer
    }

    /**
     * Method testCreatePerson
     * 
     * Tests CreatePerson
     *
     */
    @Test
    public void testCreatePerson()
    {
        controlLayer.PersonController personCo1 = new controlLayer.PersonController();
        assertEquals(true, personCo1.createPerson("test", "test", "test", "test", "123")); //opret person
        assertEquals(false, personCo1.createPerson("test", "test", "test", "test", "123")); //opret samme person
        assertEquals(true, personCo1.deletePerson("123"));
        
    }

    /**
     * Method testUpdatePerson
     * 
     * Tests UpdatePerson
     *
     */
    @Test
    public void testUpdatePerson()
    {
        controlLayer.PersonController personCo1 = new controlLayer.PersonController();
        assertEquals(true, personCo1.createPerson("test", "test", "test", "test", "123"));
        assertEquals(false, personCo1.updatePerson("234", "test2", "test2", "test2", "test2", "345")); //opdater person med forkert id
        assertEquals(true, personCo1.updatePerson("123", "test2", "test2", "test2", "test2", "789")); //opdater person med rigtigt id
        assertEquals(true, personCo1.deletePerson("789"));
    }

    /**
     * Method testFindPerson
     * 
     * Tests FindPerson
     *
     */
    @Test
    public void testFindPerson()
    {
        controlLayer.PersonController personCo1 = new controlLayer.PersonController();
        assertEquals(true, personCo1.createPerson("test", "test", "test", "test", "123"));
        assertNotNull(personCo1.findPerson("123")); //find person fra rigtigt nummer
        assertNull(personCo1.findPerson("234")); //find person fra forkert nummer
        assertEquals(true, personCo1.deletePerson("123"));
    }

    /**
     * Method testValidatePhoneNumber
     * 
     * Tests ValidatePhoneNumber
     *
     */
    @Test
    public void testValidatePhoneNumber()
    {
        controlLayer.PersonController personCo1 = new controlLayer.PersonController();
        assertEquals(true, personCo1.createPerson("test", "test", "test", "test", "123"));
        assertEquals("numberExists", personCo1.validatePhoneNumber("123")); // samme telefon nummer
        assertEquals("confirmed", personCo1.validatePhoneNumber("234")); // nyt telefon nummer
        assertEquals("letters", personCo1.validatePhoneNumber("abc")); // bogstaver i telefon nummer
        assertEquals("letters", personCo1.validatePhoneNumber("abc123")); // bogstaver og tal i telefon nummer
        assertEquals(true, personCo1.deletePerson("123"));
    }
}





